package com.ego.ware.po;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Date;

import com.ego.common.constant.WareConstant;
import com.ego.ware.vo.PurchaseVo;
import lombok.Data;

/**
 * @author KamTang
 * @program: ego
 * @description 采购信息
 * @date 2022-11-13 13:30:29
 */
@Data
@TableName("wms_purchase")
public class Purchase implements Serializable {
    private static final long serialVersionUID = 1L;

    @TableId
    private Long id;
    /**
     * 采购人ID
     */
    private Long assigneeId;
    /**
     * 采购人姓名
     */
    private String assigneeName;
    /**
     * 联系方式
     */
    private String phone;
    /**
     * 优先级
     */
    private Integer priority;
    /**
     * 状态
     */
    private Integer status;
    /**
     * 仓库ID
     */
    private Long wareId;
    /**
     * 总金额
     */
    private BigDecimal amount;
    /**
     * 创建日期
     */
    private Date createTime;
    /**
     * 更新日期
     */
    private Date updateTime;

    /**
     * 是否可被领取
     */
    public boolean available() {
        return this.getStatus().equals(WareConstant.PurchaseStatusEnum.CREATED.getCode()) ||
                this.getStatus().equals(WareConstant.PurchaseStatusEnum.ASSIGNED.getCode());
    }

    /**
     * 接收采购单中
     */
    public void receiving() {
        this.setStatus(WareConstant.PurchaseStatusEnum.RECEIVED.getCode());
        this.setUpdateTime(new Date());
    }

    /**
     * 完成采购
     */
    public void finished(Long id, boolean status) {
        this.setId(id);
        this.setStatus(status ? WareConstant.PurchaseStatusEnum.FINISHED.getCode() : WareConstant.PurchaseStatusEnum.ERROR.getCode());
        this.setUpdateTime(new Date());
    }

    public PurchaseVo toVo() {
        return BeanUtil.copyProperties(this, PurchaseVo.class);
    }
}
